import request from "@/plugins/axios";
import { ProTableRequest, ProTableResult } from "tdesign-pro-component";

export function getUserMenu() {
    return request.get<MenuResult[]>('/api/menu/user_menu');
}

export function getMenuPage(data: ProTableRequest<Partial<Menu>>) {
    //@ts-ignore
    delete data.sort;
    return request.post<ProTableResult<MenuPageVo>>('/api/menu/page', data);
}

export function getMenuChildren(button?: number) {
    return request.get<MenuWithChildren[]>('/api/menu/menu_children?button=' + (button ? 1 : 0));
}

export function createMenu(data: Partial<Menu>) {
    return request.post('/api/menu', data)
}

export function updateMenu(data: RequiredItem<Menu, 'id'>) {
    return request.put('/api/menu', data)
}

export function getMenu(id: number) {
    return request.get<Menu>('/api/menu/' + id)
}

export function deleteMenu(id: number) {
    return request.delete('/api/menu/' + id)
}